clear all

%%transform the value of the labels from pixeis to coordinates
%more than one worm at the same time; data of different worms is in
%different colums
xlabpix = xlsread ('PA to PA 8 label2.xlsx', 1);
ylabpix = xlsread ('PA to PA 8 label2.xlsx', 2);
conver = xlsread ('PA to PA 8 label2.xlsx', 3);
n = size (xlabpix, 2);
% convert the x coordinates
xlab = convertx (xlabpix,conver);
ylab = converty (ylabpix, conver);

%% find the parameters to align to the PA stimuli
%set the same value for the position of the PA stimuli - I decided these
%values in an arbitrary way to fit well in the graph
PAx = 7500;
PAy = 12500;

%found the distance between my stimulus and the specificed PA stimuli
xdistPA = PAx - xlab;
ydistPA = PAy - ylab;

%% call the values of speed, x and y
speedall = xlsread ('RRF3_exp16_ZC2834_speed_all_F1');%all the individuals to make the scale
speed = xlsread ('PA to PA 8 label2.xlsx',4);
hor = xlsread ('PA to PA 8 label2.xlsx',5);
ver = xlsread ('PA to PA 8 label2.xlsx',6);

%% normalize the x and y position to the PA stimulus

horfinal = [];%for x values horizontally
for i = 1:n;
    xdis (i) = xdistPA(1,i);
    hornorm = hor (:, i) + xdis (i);
    a = hornorm;
    horfinal = [horfinal a];
end

verfinal = [];% for y values, verticaly
for i = 1:n;
    ydis (i) = ydistPA(1,i);
    vernorm = ver (:, i) + ydis (i);
    b = vernorm;
    verfinal = [verfinal b];
end

%% find the max and min values of speed for all experiment
speedrange = velocidadef (speedall);
speedminall = speedrange (1,1);
speedmaxall = speedrange (1,2);
% normalize the speed
speedNorm = (speed - speedminall) / ( speedmaxall - speedminall) ;
%%
%% make the plot
%figure
for i=1:n
    x= horfinal (:,i);
    y= verfinal (:,i); 
    speedNormi = speedNorm (:,i);
    % to draw a circle centered in the position of the stimulus
    center = [7500, 12500];
    radius = [2000];
figure
%subplot (2,3, i);
viscircles (center, radius, 'Color', 'k');
hold on
% our plot with the coordinates x and y, size of dots 10 and color based on
% our heat map
scatter(x,y,10,speedNormi, 'filled')
colormap('jet')
box off
axis ([0,25000, 0, 25000]);
axis square
s1 = 'Worm';
s2 = i;
s3 = num2str(s2);
name = strcat(s1,s3);
title(name)
xlabel ('x')
ylabel ('y')
hold on;
end

%%  make the scale
speed0 = speedNorm (1,1); %find the value of 0 when normalized; 1st colum 1st row 
%because in the speed values the first values are always speed = 0
c = colorbar;
c.Label.String = 'Speed (um/s)';
caxis([0 1.0])% our speed is normalized from 0 to 1 so will match the scale
colorbar('Ticks',[0,speed0,1.0],...
         'TickLabels',{speedminall,0,speedmaxall});
